﻿namespace FolderConverter.NetConsole
{
    internal class Base64FileConverter
    {
        public static Base64FileInfo ConvertToBase64FileInfo(string file)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException(file);
            }

            var bytes = File.ReadAllBytes(file);
            var stringValue = Convert.ToBase64String(bytes);

            Convert.FromBase64String(stringValue);

            return new Base64FileInfo(file, stringValue);
        }

        public static FileInfo FromBase64FileInfo(Base64FileInfo base64FileInfo)
        {
            var bytes = System.Convert.FromBase64String(base64FileInfo.Content);
            return new FileInfo(base64FileInfo.Path, bytes);
        }
    }
}
